<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button type="primary" icon="el-icon-plus" @click="add"></el-button>
				<el-button type="info" icon="el-icon-refresh" @click="refresh"></el-button> 
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="search.wx_name" placeholder="昵称" clearable></el-input>
					<el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" stripe>

                <el-table-column label="头像" prop="goods" width="120" align="center">
                    <template #default="scope">
                        <el-image class="feng" :src="scope.row.avator" :fit="fit" />
                    </template>
                        
                </el-table-column>
                <el-table-column label="昵称" prop="wx_name" width="250" align="left"> </el-table-column>
                <el-table-column label="兑换商品" prop="pro_title" width="280" align="left"></el-table-column> 
				<el-table-column label="消耗积分" prop="jifen" width="250" align="center">
                        <template #default="scope">
                               <span class="red">{{scope.row.jifen}}</span>
                        </template>
                </el-table-column>
				<el-table-column label="时间" prop="time" width="180" align="center"> </el-table-column>
  
			 
			</scTable>
		</el-main>

		<savecat-dialog v-if="dialog.save" ref="savecatDialog" @success="handleSaveSuccess" @closed="dialog.save=false"></savecat-dialog>

	</el-container>
</template>

<script>
	import savecatDialog from './jifen_save'
	export default {
		name: 'mk_jifen',
		components: {
			savecatDialog
		},
		data() {
			return {
				dialog: {
					save: false
				},
				apiObj: this.$API.system.mk.jifen_record,
				selection: [],
				search: {
					keyword: null
				}
			}
		},
		methods: {
			//添加
			add(){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.savecatDialog.open()
				})
			},
			//编辑
			table_edit(row){
				this.dialog.save = true
				this.$nextTick(() => {
					this.$refs.savecatDialog.open('edit').setData(row)
				})
			},
			//删除
			async table_del(row){
				var reqData = {id: row.id,'act':'del'}
				var res = await this.$API.system.universal.handle.post(reqData,'/mk/jifen_del');
				if(res.code == 200){
					this.$refs.table.refresh()
					this.$message.success("删除成功")
				}else{
					this.$alert(res.message, "提示", {type: 'error'})
				}
			},
			//批量删除
			async batch_del(){
				this.$confirm(`确定删除选中的 ${this.selection.length} 项吗？如果删除项中含有子集将会被一并删除`, '提示', {
					type: 'warning'
				}).then(() => {
					var arr = this.selection
					var ob = []
					for(var i=0;i<arr.length;i++){
						  ob.push(arr[i].cid)
					}
					this.table_del({'cid':ob.join(",")})
				}).catch(() => {

				})
			},
			//表格选择后回调事件 
			selectionChange(selection){
				this.selection = selection;
			},
			//表格内开关
			async changeSwitch(val, row){
				var res = await this.$API.system.universal.handle.post({'id':row.id,'status':val},'/mk/jifen_save')
				if(res.code == 200){
					this.visible = false;
					this.$message.success("操作成功")
				}else{
					this.$alert(res.message, "提示", {type: 'error'})
				}
			},
			//搜索
			upsearch(){
				this.$refs.table.upData(this.search)
			},
            refresh(){
                this.$refs.table.reload()
            },
			//本地更新数据
			handleSaveSuccess(data, mode){
				if(mode=='add' || mode =='edit'){
					this.$refs.table.reload()
				}
			}
		}
	}
</script>

<style>
.red{
    font-size: 15px;
    color:#ff3333
}
.feng{
    width:40px;
    height:40px;
	border-radius: 800px
 
}
</style>

